package com.sz.admin.datainfo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sz.admin.datainfo.pojo.dto.MonitorFileRecordCreateDTO;
import com.sz.admin.datainfo.pojo.dto.MonitorFileRecordListDTO;
import com.sz.admin.datainfo.pojo.dto.MonitorFileRecordUpdateDTO;
import com.sz.admin.datainfo.pojo.vo.MonitorFileRecordVO;
import com.sz.admin.datainfo.service.MonitorFileRecordService;
import com.sz.core.common.constant.GlobalConstant;
import com.sz.core.common.entity.ApiPageResult;
import com.sz.core.common.entity.ApiResult;
import com.sz.core.common.entity.PageResult;
import com.sz.core.common.entity.SelectIdsDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 监控文件记录管理 前端控制器
 * </p>
 *
 * @author sz-admin
 * @since 2025-09-16
 */
@Tag(name = "监控文件记录管理")
@RestController
@RequestMapping("/monitor-file-record")
@RequiredArgsConstructor
public class MonitorFileRecordController {

    private final MonitorFileRecordService monitorFileRecordService;

    @Operation(summary = "添加监控文件记录")
    @SaCheckPermission(value = "monitor.file.record.create_btn", orRole = GlobalConstant.SUPER_ROLE)
    @PostMapping
    public ApiResult<Void> create(@Valid @RequestBody MonitorFileRecordCreateDTO dto) {
        monitorFileRecordService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改监控文件记录")
    @SaCheckPermission(value = "monitor.file.record.update_btn", orRole = GlobalConstant.SUPER_ROLE)
    @PutMapping("/update")
    public ApiResult<Void> update(@Valid @RequestBody MonitorFileRecordUpdateDTO dto) {
        monitorFileRecordService.update(dto);
        return ApiResult.success();
    }
    
    @Operation(summary = "编辑监控文件记录")
    @SaCheckPermission(value = "monitor.file.record.update_btn", orRole = GlobalConstant.SUPER_ROLE)
    @PutMapping("/edit")
    public ApiResult<Void> edit(@Valid @RequestBody MonitorFileRecordUpdateDTO dto) {
        monitorFileRecordService.edit(dto);
        return ApiResult.success();
    }

    @Operation(summary = "查询分页列表")
    @SaCheckPermission(value = "monitor.file.record.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping("/page")
    public ApiPageResult<PageResult<MonitorFileRecordVO>> page(MonitorFileRecordListDTO dto) {
        return ApiPageResult.success(monitorFileRecordService.page(dto));
    }

    @Operation(summary = "查询列表")
    @SaCheckPermission(value = "monitor.file.record.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping("/list")
    public ApiResult<List<MonitorFileRecordVO>> list(MonitorFileRecordListDTO dto) {
        return ApiResult.success(monitorFileRecordService.list(dto));
    }

    @Operation(summary = "批量删除")
    @SaCheckPermission(value = "monitor.file.record.delete_btn", orRole = GlobalConstant.SUPER_ROLE)
    @DeleteMapping
    public ApiResult<Void> remove(@Valid @RequestBody SelectIdsDTO dto) {
        monitorFileRecordService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "详情")
    @SaCheckPermission(value = "monitor.file.record.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping("/{id}")
    public ApiResult<MonitorFileRecordVO> detail(@PathVariable Long id) {
        return ApiResult.success(monitorFileRecordService.detail(id));
    }
}